<template>
	<view class="top-nav-container">
		<scroll-view class="top-nav-scroll" scroll-x="true" :show-scrollbar="false" :scroll-with-animation="true"
			:enhanced="true">
			<view v-for="(item, index) in navItems" :key="index" class="nav-item"
				:class="{ active: selectedIndex === index }" @click="selectNavItem(index)">
				{{ item }}
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		name: "TopView",
		data() {
			return {
				selectedIndex: 0,
				navItems: ["推荐", "关注", "24小时", "本地", "娱乐", "社会", "股市"]
			};
		},
		methods: {
			selectNavItem(index) {
				this.selectedIndex = index;
				this.$emit("tabChange", index);
			}
		}
	};
</script>

<style scoped>
	.top-nav-container {
		width: 100%;
		background-color: #b00000;
	}

	.top-nav-scroll {
		white-space: nowrap;
		width: 100%;
		padding: 20rpx 20rpx 10rpx;
		overflow-x: hidden;
		-webkit-overflow-scrolling: auto;
	}

	.nav-item {
		display: inline-block;
		padding: 12rpx 24rpx;
		font-size: 32rpx;
		color: #333333;
		text-align: center;
		border-radius: 8rpx;
		margin-right: 20rpx;
		min-width: 80rpx;
	}

	.nav-item:last-child {
		margin-right: 0;
	}

	.nav-item.active {
		color: #007AFF;
		font-weight: bold;
	}
</style>